package 典型.操作系统;

import java.util.Random;
import java.util.concurrent.TimeUnit;

public class Consumer {
    public static void main(String[] args) {
        Product product = new Product();
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    try {
                        product.consume2();
                        TimeUnit.SECONDS.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                while (true) {
                    try {
                        product.provide2();
                        TimeUnit.SECONDS.sleep(3);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        for (int i = 0; i < 3; i++) {
            new Thread(runnable).start();
        }

    }
}
